先看一下结果···
点开有详细解释哦~
直接上代码12345678910111213141516171819202122232425262728293031323334353637383940class father{ public int f = 1; father(){ show(); //show() 此时被子类重写 //且子类中未显示初始化,故打印"son block---0" } void show(){ System.out.println("father---"+f); } static{ System.out.println("father static block---"); } { System.out.println("father block---"+f); }}class son extends father{ public int s = 2; son(){ super();//第一步 //第二部:显示初始化,为 s 初始化 //第三部:构造代码块初始化,打印 "son block---2" show(); } void show(){ System.out.println("son---"+s); } static{ System.out.println("son static block---"); } { System.out.println("son block---"+s); }}class test{ public static void main(String[] args){ new son(); } }